﻿//tamt	2009/08/21
//-------------界面文件的生成----------------------
var tmpXmlFile = fl.configURI + "/tmp.xml";
var xmlGui = buildXulGui();
FLfile.write(tmpXmlFile, xmlGui);
function buildXulGui()
{
 	return '<dialog id="dialog" title="批量修改库中链接类名" buttons="accept, cancel"> \
     <vbox> \
      <label width="300" value="批量替换库中所有元件链接类名的字符串."/> \
      <textbox width="300" value="SCBaseWindowLV2." id="str"/> \
      <label value="替换成: " /> \
      <textbox value="SCTerranBase.SCBaseWindowLV2." width="300" id="repStr"/> \
      <separator/> \
	  <label width="300" value="给所有链接类名增加前缀."/> \
	  <textbox width="300" value="" id="prefix"/> \
    </vbox> \
    \
  </dialog>';
}
//-------------------------------------------------
var setting = fl.getDocumentDOM().xmlPanel(tmpXmlFile);
if(setting.dismiss=='accept'){
	var items = fl.getDocumentDOM().library.items;
	var repi = 0;
	for(var i=0; i<items.length; i++){
		var item = items[i];
		if(setting.str.length>0){
			if(item.linkageBaseClass && item.linkageBaseClass.indexOf(setting.str)==0){
				var tmp = item.linkageBaseClass;
				item.linkageBaseClass = setting.repStr + tmp.substring(setting.str.length, tmp.length);
				repi++;
			}
			if(item.linkageClassName && item.linkageClassName.indexOf(setting.str)==0){
				var tmp = item.linkageClassName;
				item.linkageClassName = setting.repStr + tmp.substring(setting.str.length, tmp.length);
				repi++;
			}
		}
		if(setting.prefix.length>0){
			if(item.linkageClassName){
				var tmp = item.linkageClassName;
				item.linkageClassName = setting.prefix + tmp;
				repi++;
			}
		}
	}
	
	//更新显示
	fl.getDocumentDOM().library.selectItem(items[0]['name']);
	fl.getDocumentDOM().library.selectNone();
	alert('总共替换: ' + repi);
}